import pandas

food_info = pandas.read_csv('food_info.csv')
print(type(food_info))
print(food_info.dtypes)

# fist 5 lines
first_rows = food_info.head()
print(first_rows)

# fist 3 lines
print(food_info.head(3))

# columns name
print(food_info.columns)

# (8618, 36)
print(food_info.shape)

# pandas uses zero-indexing
# Series object representing the row at index 0
print(food_info.loc[0])
# Series object representing the 7th row.
print(food_info.loc[6])

# Will throw an error: KeyError: 'the label [8620] is not in the [index]'
# food_info.loc[8620]

# The object dtype is equivalent to a string in Python
# object - For string values
# int - For Integer values
# float - For float values
# datetime - For time values
# bool - For Boolean values
print(food_info.dtypes)

# Returns a DataFame containing the rows at
# indexes 3,4,5, and 6
print(food_info.loc[3:6])

# Returns a DataFrame containing the rows at
# indexes 2, 5, 10
# Method 1:
# Pleas do pay attention to the pattern : food_info.loc[[2, 5, 10]]
# pass a LIST!!![2, 5, 10]
print(food_info.loc[[2, 5, 10]])
two_five_ten = [2, 5, 10]
# Method 2:
print(food_info.loc[two_five_ten])

# Series object representing the 'NDB_No' column
ndb_col = food_info["NDB_No"]
print(ndb_col)
# Alternatively, you can access a column by passing in
# a String value.
col_name = 'Vit_K_(mcg)'
ndb_col = food_info[col_name]
print(ndb_col)

columns = ['Shrt_Desc', 'Water_(g)', 'Energ_Kcal']
desc_water_eng = food_info[columns]
print(desc_water_eng)

print(food_info[['Shrt_Desc', 'Water_(g)', 'Energ_Kcal']])

# total columns names
print(food_info.columns)

# Question: show all columns names including (g)
col_names = food_info.columns.tolist()
print(col_names)
gram_columns = []
for c in col_names:
    if c.endswith('(g)'):
        gram_columns.append(c)
gram_df = food_info[gram_columns]
print(gram_df.head(3))

